package edu.umn.contactviewer;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

import edu.umn.contactviewer.models.Contact;

/** Displays a contact's information.
 *
 */
public class ContactInfoActivity extends Activity implements View.OnClickListener {
    private Contact contact;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.contact_info);
        ToolbarConfig toolbarConfig = new ToolbarConfig(this, "Details");
        toolbarConfig.getToolbarBackButton().setText( "Contacts" );
        toolbarConfig.getToolbarRightButton().setText( "Edit" );

        Bundle b = this.getIntent().getExtras();
        contact = (Contact) b.getSerializable("contact");

        ((TextView)findViewById(R.id.contact_name)).setText(contact.getName());
        ((TextView)findViewById(R.id.contact_title)).setText(contact.getTitle() + " ");
        ((TextView)findViewById(R.id.twitter)).setText("Twitter ID:");
        ((TextView)findViewById(R.id.contact_twitter)).setText(contact.getTwitterId());
        ((TextView)findViewById(R.id.email)).setText("Email:");
        ((TextView)findViewById(R.id.contact_email)).setText(contact.getEmail());
        ((TextView)findViewById(R.id.phone)).setText("Phone:");
        ((TextView)findViewById(R.id.contact_phone)).setText(contact.getPhone());

        findViewById(R.id.toolbar_right_button).setOnClickListener(this);
        
        findViewById(R.id.toolbar_back_button).setOnClickListener(this);

    }

    public void onClick(View view) {
        if (view.getId() == R.id.toolbar_right_button) {
            Bundle bundle = new Bundle();
            bundle.putSerializable("contact", contact);
            Intent intent = new Intent();
            intent.setClass(ContactInfoActivity.this, ContactEditActivity.class);
            intent.putExtras(bundle);
            startActivity(intent);
        }
        else if (view.getId() == R.id.toolbar_back_button) {
            Intent intent = new Intent(this, ContactListActivity.class);
            startActivity(intent);
            overridePendingTransition( R.anim.slide_in_right, R.anim.slide_out_right );
        }
    }
}
